package com.example.chat_websocket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.chat_websocket.mapper.UserMapper;
import com.example.chat_websocket.pojo.User;
import com.example.chat_websocket.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Author 张云飞
 * @Date 2021/10/29 0029 21:44
 * @注释
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUser(String username, String password) {
        LambdaQueryWrapper<User> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getUsername,username).eq(User::getPassword,password);
        return userMapper.selectOne(lambdaQueryWrapper);
    }

    @Override
    public User findByUsername(String username) {
        return this.userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername,username));
    }

    @Override
    public void save(User user) {
        this.userMapper.insert(user);
    }
}
